using Godot;
using System;

namespace ZerAx.Roguelike
{
	[Tool]
	public partial class Tile : Node2D
	{
		private Dir _dir;
		[Export(PropertyHint.Flags)]
		public Dir Dir
		{
			get => _dir;
			set
			{
				_dir = value;
				QueueRedraw();
			}
		}

		[Export]
		public bool RotateClockwise { get => true; set => Dir = Dir.RotateCw(); }
		[Export]
		public bool RotateCounterClockwise { get => true; set => Dir = Dir.RotateCcw(); }

        public override void _Draw()
        {
			var white = new Color(0xffffffff);
			var red = new Color(0xff0000ff);

			DrawRect(new(Vector2.Zero, Vector2.One), white);
			if (Dir.HasFlag(Dir.West))
			{
				DrawRect(new(0.4f * Vector2.Down, new(0.6f, 0.2f)), red);
			}
			if (Dir.HasFlag(Dir.East))
			{
				DrawRect(new(new(0.4f, 0.4f), new(0.6f, 0.2f)), red);
			}
			if (Dir.HasFlag(Dir.North))
			{
				DrawRect(new(0.4f * Vector2.Right, new(0.2f, 0.6f)), red);
			}
			if (Dir.HasFlag(Dir.South))
			{
				DrawRect(new(new(0.4f, 0.4f), new(0.2f, 0.6f)), red);
			}
        }
    }
}